<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<!-- 用包含的形式引入文件 -->
<%@ include file="/web/header.jsp" %>
<title>用户注册</title>
</head>
<!-- http://127.0.0.1:8080/GraduationProject/web/reg.jsp -->
<body style="background:#f1f1f1">

<div class="window">
<fieldset class='layui-elem-field' style="margin:10px">
<legend>注册</legend>

<div class="layui-field-box">
<form class="layui-form layui-form-pane" method="post">

<div class="layui.form-item">
<label class="layui-form-label">账号：</label>
<div class='layui-input-inline'>
<input type="text" name="code" class="layui-input" placeholder="请输入账号：">
</div>
</div>

<div class="layui.form-item">
<label class="layui-form-label">密码：</label>
<div class='layui-input-inline'>
<input type="text" name="pass" class="layui-input" placeholder="请输入密码：">
</div>
</div>

<div class="layui.form-item">
<label class="layui-form-label">姓名：</label>
<div class='layui-input-inline'>
<input type="text" name="name" class="layui-input" placeholder="请输入姓名：">
</div>
</div>

<div class="layui.form-item">
<div class='layui-input-inline'>
<input type="button" value="注册" class="layui-btn" 
lay-submit lay-filter="reg">
<input type="reset" value="重置" class="layui-btn layui-btn-primary">
</div>
<input type="button" value="返回登陆" class="layui-btn" onclick="toLogin()">
</div>


<input type="hidden" name='action' value="reg">
</form>
</div>
</fieldset>
</div>

<script type="text/javascript">
var form=layui.form,$=layui.jquery,layer=layui.layer;
form.on("submit(reg)",function(data){
	$.ajax({
		url:base.app+"/employee",//访问的工程名,base.app是在header定义的
		type:"post",
		data:data.field,
		dataType:"text",
		success:function(data){
			//console.log(data)
			//判断返回的参数，根据参数提示信息
			if(data==1){
				layer.msg("注册成功")
			}else if(data=="repeat"){
				layer.msg("注册失败，账号重复")
			}
		}
	})
})

//引入了提炼之后的js 代码后，上面那段代码可简写为如下：
// formSubmit('/employee','submit(reg)','text',function(data){
// 	//console.log(data)
// 	//判断返回的参数，根据参数提示信息
// 	if(data==1){
// 		layer.msg("注册成功")
// 	}else if(data=="repeat"){
// 		layer.msg("注册失败，账号重复")
// 	}
// })

function toLogin(){
	location.href=base.app+"/web/login.jsp"
}
</script>
</body>
</html>